import { useMemberStore } from "./../store/modules/member";
import { PageResult } from "../types/global";
import type {
  TaskCommentCreate,
  TaskCommentItem,
  TaskCommentReply,
  TaskCreateParams,
  TaskIndexParams,
  TaskItem,
  TaskUpdate,
} from "../types/task";
import http from "../utils/http";

// 任务列表
export const postTaskList = (data: TaskIndexParams) => {
  return http<PageResult<TaskItem[]>>({
    url: "Task/index",
    method: "POST",
    data,
  });
};

// 任务分类列表
export const postTaskCategory = () => {
  return http<PageResult<TaskItem[]>>({
    url: "Task/category",
    method: "POST",
  });
};

// 任务详情
export const postTaskDetail = (id: number) => {
  return http<TaskItem>({
    url: "Task/view",
    method: "POST",
    data: {
      id,
    },
  });
};

// 我的任务
export const postMemberTaskList = (data) => {
  return http<PageResult<TaskItem[]>>({
    url: "Task/my",
    method: "POST",
    data
  });
};

// 发布任务
export const postCreateTask = (data: TaskCreateParams) => {
  return http<any>({
    url: "Task/create",
    method: "POST",
    data,
  });
};

// 用户接收的任务
export const postProfileTask = (status: number) => {
  return http<PageResult<TaskItem[]>>({
    url: "Task/my_receive",
    method: "POST",
    data: {
      status,
    },
  });
};

// 修改任务
export const postUpdateTask = (data: TaskUpdate) => {
  return http<any>({
    url: "Task/update",
    method: "POST",
    data,
  });
};

// 删除任务
export const postDeleteTask = (id: number) => {
  return http<any>({
    url: "Task/destory",
    method: "POST",
    data: {
      id,
    },
  });
};

// 发布者-确认完结
export const postTaskFinish = (id: number) => {
  return http<any>({
    url: "Task/finish",
    method: "POST",
    data: {
      id,
    },
  });
};

// 发布评论
export const postTaskCommentCreate = (data: TaskCommentCreate) => {
  return http<any>({
    url: "TaskComment/create",
    method: "POST",
    data,
  });
};

// 回复评论
export const postTaskCommentReplay = (data: any) => {
  return http<any>({
    url: "TaskComment/replay",
    method: "POST",
    data,
  });
};

// 任务评论列表
export const postTaskCommentList = (task_id: number,page:number) => {
  return http<PageResult<TaskCommentItem[]>>({
    url: "TaskComment/index",
    method: "POST",
    data: {
      task_id,
      page,
      rows: 10
    },
  });
};

// 抢单
export const postTaskReceive = (id: number) => {
  const { profile } = useMemberStore();
  return http<any>({
    url: "Task/receive",
    method: "POST",
    data: {
      id,
      member_id: profile!.id,
    },
  });
};

// 删除评论
export const postTaskCommentDelete = (id: any) => {
  return http<any>({
    url: "TaskComment/destory",
    method: "POST",
    data: {
      id,
    },
  });
};

// 跟进
export const postTaskFollowUp = (data: TaskCreateParams) => {
  const { profile } = useMemberStore();
  return http<any>({
    url: "task/log",
    method: "POST",
    data: {
      ...data,
      member_id: profile!.id,
    },
  });
};

// 跟进记录
export const postTaskFollowUpList = (id: any) => {
  return http<any>({
    url: "task/task_log",
    method: "POST",
    data: {
      task_id: id,
    },
  });
};

// 订单-申请结单
export const postTaskFollowUpToStatement = (task_id: any) => {
  return http<any>({
    url: "task/applicant",
    method: "POST",
    data: {
      task_id,
    },
  });
};


// 指派用户列表
export const postTaskOrderList = (id: any) => {
  return http<any>({
    url: "Task/member",
    method: "POST",
    data: {
      task_id: id,
    },
  });
};

// 指派用户
export const postTaskOrderToUser = (data: { task_id; member_id }) => {
  return http<any>({
    url: "Task/order",
    method: "POST",
    data,
  });
};
